﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Wpf.Activation.Demo1
{
    /// <summary>
    /// WinSerial.xaml 的交互逻辑
    /// </summary>
    public partial class WinSerial : Window
    {
        public WinSerial()
        {
            InitializeComponent();
        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            string licenseKey = licenseTextBox.Text;
            if (ValidateLicenseKey(licenseKey))
            {
                SaveLicenseKey(licenseKey);
                MessageBox.Show("激活成功!", "激活成功", MessageBoxButton.OK, MessageBoxImage.Information);
                this.DialogResult = true;
            }
            else
            {
                MessageBox.Show("序列号不正确!", "激活失败", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private bool ValidateLicenseKey(string licenseKey)
        {
            // 这里应该是验证注册码的逻辑，例如与服务器通信或其他逻辑
            return licenseKey == "NYW94-47Q7H-7X9TT-W7TXD-JTYPM";
        }

        private void SaveLicenseKey(string licenseKey)
        {
            // 将注册码保存至app.config或其他位置
            // 例如：Properties.Settings.Default.LicenseKey = licenseKey;
            // Properties.Settings.Default.Save();
        }
    }
}
